package cn.operation.backend.service;

import cn.operation.backend.util.PageVo;
import cn.operation.base.mapper.ScPriceSaleOlTpMapper;
import cn.operation.base.model.LinePriceSaleOlTpTool;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.math.BigDecimal;
import java.util.List;

/**
 * @FileName:
 * @Description: Description
 * @author: Aaron
 * @date: 2016/11/2 下午4:04
 */
@Service
public class PriceSaleOlTpServiceImpl implements PriceSaleOlTpService {

	@Autowired
	private ScPriceSaleOlTpMapper scPriceSaleOlTpMapper;

	private static final Logger LOGGER = LoggerFactory.getLogger(PriceSaleOlTpServiceImpl.class);


	@Override
	public List<LinePriceSaleOlTpTool> selectPrice(PageVo pageVo, Integer startAreaId, Integer endAreaId) throws Exception {
		LOGGER.info("PriceSaleOlTpServiceImpl.selectPrice params : {}, {}", pageVo, startAreaId, endAreaId);

		if (null == startAreaId) {
			LOGGER.error("PriceSaleOlTpServiceImpl.selectPrice param  must not be null ");
			throw new IllegalArgumentException("起点区域ID不能为空");
		}

		if (null == startAreaId) {
			LOGGER.error("PriceSaleOlTpServiceImpl.selectPrice param  must not be null ");
			throw new IllegalArgumentException("终点区域ID不能为空");
		}

		String orderByClause = null;
		Integer limitStart = null;
		Integer limitEnd = null;
		if (null != pageVo) {
			orderByClause = StringUtils.isNotBlank(pageVo.getOrder()) == true ? pageVo.getOrder() : " lineId DESC";
			limitStart = pageVo.getStartIndex();
			limitEnd = pageVo.getPageSize();
		}

		List<LinePriceSaleOlTpTool> list = scPriceSaleOlTpMapper.selectMileagePriceSaleOlTp(startAreaId, endAreaId, orderByClause, limitStart, limitEnd);
		if (list != null && list.size() == 0) {
			LinePriceSaleOlTpTool linePriceSaleOlTpTool = new LinePriceSaleOlTpTool();
			linePriceSaleOlTpTool.setCarryToolId(0);
			linePriceSaleOlTpTool.setLineId(0);
			linePriceSaleOlTpTool.setProgramId(0);
			linePriceSaleOlTpTool.setMileage(new BigDecimal(0));
			linePriceSaleOlTpTool.setLtlUnitPrice(new BigDecimal(0));
			linePriceSaleOlTpTool.setLtlGrossPrice(new BigDecimal(0));
			linePriceSaleOlTpTool.setTlUnitPrice(new BigDecimal(0));
			linePriceSaleOlTpTool.setTlGrossPrice(new BigDecimal(0));
			linePriceSaleOlTpTool.setTransModeCode("0");
			linePriceSaleOlTpTool.setTransModeName("0");
			linePriceSaleOlTpTool.setCarryToolId(0);
			linePriceSaleOlTpTool.setUnitPrice(new BigDecimal(0));
			list.add(linePriceSaleOlTpTool);
			return list;
		}
		return list;
	}
}
